package com.starter;

import java.io.File;
import java.io.InputStream;
import java.util.List;

import com.downloaduploadspeed.DownloadUploadSpeed;
import com.image.ImageTransformCloud;
import com.image.ImageTransformLocal;
import com.listsorter.ListSorterLocal;
import com.listsorter.ListSorterCloud;
import com.primecalc.PrimeCalcLocal;
import com.primecalc.PrimeCalcCloud;

public class Starter {
	
	private DataSaver data;
	private String key = "1234";
	
	public void dataSaverInit() {
		this.data = new DataSaver();
		this.data.setKey(this.key);
	}
	
	public void downloadUploadSpeed(File filen, File downloadTempFile) {
//		try {
//			String urlUpload = "http://example.appspot.com/upload?validate=1234";
//			String urlDownload = "http://example.appspot.com/serve?validate=1234";
//			
//			DownloadUploadSpeed downUpSpeed = new DownloadUploadSpeed();
//			this.data.setDownloadSpeed(Float.toString(downUpSpeed.downloadUrl(downloadTempFile, urlDownload)));
//			this.data.setUploadSpeed(Float.toString(downUpSpeed.uploadUrl(filen, urlUpload)));
//			this.data.setErrorMessage(downUpSpeed.getErrorMessage());
//		} catch (Exception e) {
//			this.data.setErrorMessage("Starter.uploadDownloadSpeed(): " + e);
//		}
	}
	
	public void primeCalc(int times) {
	//public String primeCalc() {
		String inUrl = "http://windmsb.appspot.com/";
		System.out.println("Cal Is Cal: " + inUrl);
		PrimeCalcLocal primeCalc = new PrimeCalcLocal();
		//
		primeCalc.calculatePrimeNumbers();
		String primeCalcLocalTest = primeCalc.returnNumber();
		this.data.setPrimeCalcLocalResult(Float.toString(primeCalc.returnTime()));
		
		PrimeCalcCloud primeInteract = new PrimeCalcCloud();
		primeInteract.primeInteract(inUrl);
		this.data.setErrorMessage(primeInteract.errorMessage());
		String primeCalcCloudTest = primeInteract.returnNumber();
		this.data.setPrimeCalcCloudResult(Float.toString(primeInteract.returnTime()));
		this.data.setTestData(primeCalcLocalTest + "==" + primeCalcCloudTest +"&");
		
		//
		//return primeCalcLocalTest + "-" + primeCalcCloudTest;
	}
	
	public void listSorter(List<String> wordList, String textString) {
	//public String listSorter(List<String> wordList, String textString) {
		String urlForm = "http://windmsb.appspot.com/";		
		String urlPost = "http://windmsb.appspot.com/";
		
//		ListSorterLocal listSorter = new ListSorterLocal();
		// listSorter.listSorter(wordList);
//		String listSortLocal = listSorter.listSorter(wordList);
//		this.data.setListSorterLocalResult(Float.toString(listSorter.returnTime()));
//		this.data.setErrorMessage(listSorter.errorMessage());
		
		ListSorterCloud listSorterCloud = new ListSorterCloud();
		// listSorterCloud.listSorterCloud(textString, urlForm, urlPost);
		String listSortCloud = listSorterCloud.listSorterCloud(textString, urlForm, urlPost);
//		this.data.setListSorterCloudResult(Float.toString(listSorterCloud.returnTime()));
//		this.data.setErrorMessage(listSorterCloud.errorMessage());
//		this.data.setTestData(listSortLocal + "==" + listSortCloud+"&");

		//return "ListSortLocal: " + listSortLocal + " ListSorterCloud: " + listSortCloud;
	}
	
	//public void imageTran(InputStream in, File filen, File tempSaveImage) {		
	public void imageTran(InputStream in, File filen, File tempSaveImage1, File tempSaveImage2) {		
//		ImageTransformLocal local = new ImageTransformLocal();
//		String imageTransformLocal = local.localImageSizeFlip(in, tempSaveImage1);
//		this.data.setImageTransformLocalResult(Float.toString(local.returnTime()));
//		this.data.setErrorMessage(local.errorMessage());
//		
//		String urlIn = "http://example.appspot.com/upload?validate=1234";
//		ImageTransformCloud cloud = new ImageTransformCloud();
//		String imageTransformCloud = cloud.imageCloud(urlIn, filen, tempSaveImage2);
//		this.data.setImageTransformCloudResult(Float.toString(cloud.returnTime()));
//		this.data.setErrorMessage(cloud.errorMessage());
//		this.data.setTestData(imageTransformLocal + "==" + imageTransformCloud);
//		
//		//return imageTransformLocal + "==" + imageTransformCloud;
	} 
	
	public void savePhoneInfo(String phoneModel, String fingerPrint, String phoneSDK, String connectionInfo) {
		this.data.setPhoneDetails(phoneModel, fingerPrint, phoneSDK, connectionInfo);
	}
	
	public void dataSaverFinnish() {
		String urlGet = "http://example.appspot.com/";
		String urlPost = "http://example.appspot.com/appenginedatasaver";
		this.data.sendResults(urlGet, urlPost);
	}
}